package com.ld.security.gateway.filter;

import org.springframework.http.HttpCookie;
import org.springframework.http.server.reactive.ServerHttpRequest;

public class TokenUtil {


    public static boolean splitStr(String url,int ind,String key){
        String[] strs = url.split("/");
        if(ind < strs.length){
            return strs[ind].equals(key);
        }else{
            return true;
        }
    }



    public static String getToken(ServerHttpRequest request,String tokenKey){
        String token = null;
        token = request.getQueryParams().getFirst(tokenKey);


        if(token == null){
            HttpCookie cookie = request.getCookies().getFirst(tokenKey);
            if(cookie != null){
                token =cookie.getValue();
            }

        }
        if(token == null){
           token =  request.getHeaders().getFirst(tokenKey);
        }
        return token;
    }


}
